package com.jinghong.registerlogin.mapper;
import com.jinghong.registerlogin.model.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * ClassName:UserMapper
 * Package:com.jingjian.gamesetupapp.mapper
 * Description:
 *
 * @Author: 寻月君子
 * @CreatTime:2023/12/18 20:10
 * Version:1.0
 */
@Mapper
public interface UserMapper {
    /**
     * 根据用户名查询用户
     * @param username 用户名
     * @return user 用户
     */
    @Select("select * from `register_login`.user where username=#{username}")
    User findByUserName(String username);

    /**
     *
     * @param user
     */
    @Insert("insert into `register_login`.user(username,password,is_admin,creat_time,update_time)" +
            " values(#{username},#{password},#{isAdmin},now(),now())")
    void add(User user);

    /**
     * 根据ID更新用户信息
     * @param user  用户信息
     */
    void update(User user);


    /**
     *
     * @param userId 用户id
     * @param isAdmin 是否管理员
     */
    @Update("update `register_login`.user set is_admin = #{isAdmin} where id = #{userId}")
    void updateIsAdmin(Integer userId, Integer isAdmin);
}
